//
//  addbaojiaViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/18.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//
#import "editCaseViewController.h"
#import "webCollectionViewCell.h"
#import "HAODEsingleton.h"
#import "HttpRequest.h"
#import "RDVTabBarController.h"
#import "UIViewExt.h"
#import "ProductView.h"
#import "GetProductListViewController.h"
#import "addguigeCell.h"
#import "VPImageCropperViewController.h"
#import "UpYun.h"
#import "mianjiViewController.h"
#import "huxingViewController.h"
#import "fenggeViewController.h"
#import "casetupianCell.h"
#import "UIButton+WebCache.h"
@interface editCaseViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIActionSheetDelegate, UICollectionViewDelegateFlowLayout,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate,UITextFieldDelegate,UITextViewDelegate>
{
    NSMutableArray *imageArray;
    NSMutableArray *imageArray1;
    HAODEsingleton *commdity;
    UIButton*Btn;
    UITextField*titleTextFied;
    UITextField*leibieTextFied;
    UITextField*mingchengTextFied;
    UITextField*kucunTextFied;
    UITextView*tv;
    UIImageView*imagess;
    UITextField*jiageTextFied;
    UIView*myToolBar;
    UIScrollView*myscrollView;
    UIView*view2;
    UIView*view1;
    UIView*view;
    UIView*biaoqianview;
    ProductView *clothView;
    NSMutableArray* arrrs;
    NSMutableArray *selectFeatureCodeArray;
    NSMutableArray *specName;
    NSMutableArray *specPrice;
    NSMutableArray *specInv;
    BOOL saveAccount;
    UIView*guigeview;
    UIView*guigeviews;
    int pageNumber;
    UIButton*shanchuBtn;
    UIButton* tianjiashanping;
    UILabel* jiage;
    UILabel* kucun;
    UIView*view33;
    NSMutableArray*imageList;
    UILabel*label;
    NSString* sat;
    NSMutableArray*itemList;
}
@end

@implementation editCaseViewController
@synthesize alt = alt;
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    self.navigationController.delegate = nil;
    
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    
    
    imageArray1 = [NSMutableArray arrayWithObjects:nil];
    itemList=commdity.itemIdarr;
    imageArray1=commdity.imageUrlFullarr;
    
    if ([sat isEqualToString:@"guanglian"]) {
        
        [view removeFromSuperview];
        view=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 250)];
        view.backgroundColor=[UIColor whiteColor];
        [myscrollView addSubview:view];
        
        
        if (imageArray1.count>0) {
            
            
            for (int i = 0,j = -1; i <imageArray1.count+1; i++) {
                if (i%4 == 0) {
                    j++;
                }
                if (imageArray1.count==i) {
                    UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15+(ScreenWidth-30)/4*(i%4), 20+(ScreenWidth-40)/4*j, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                    [imageView setImage:[UIImage imageNamed:@"tianjiatupain"] forState:UIControlStateNormal];
                    [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                    imageView.tag=imageArray1.count;
                    [view addSubview:imageView];
                }else{
                    UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15+(ScreenWidth-30)/4*(i%4), 20+(ScreenWidth-40)/4*j, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                    [imageView setImageWithURL:[NSURL URLWithString:[imageArray1  objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@""]];
                    [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                    imageView.tag=i;
                    [view addSubview:imageView];
                }
                
            }
        }else{
            UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15, 20, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
            [imageView setImage:[UIImage imageNamed:@"tianjiatupain"] forState:UIControlStateNormal];
            [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
            imageView.tag=imageArray1.count;
            [view addSubview:imageView];
        }
        
        
    }
    
    
    leibieTextFied.text=commdity.content;
    mingchengTextFied.text=commdity.caseStylecontent;
    kucunTextFied.text=commdity.caseHousecontent;
       
    if (jiageTextFied.text.length>0) {
        titleTextFied.text=[NSString stringWithFormat:@"%@ %@㎡ %@",mingchengTextFied.text,jiageTextFied.text,kucunTextFied.text];
        
    }else{
        titleTextFied.text=[NSString stringWithFormat:@"%@ %@ %@",mingchengTextFied.text,jiageTextFied.text,kucunTextFied.text];
        
    }
    
}
-(void)viewDidLoad{
    
    [super viewDidLoad];
    
    
    
    NSUserDefaults *user11 = [NSUserDefaults standardUserDefaults];
    NSString* Token11 = [user11 objectForKey:@"tokenId"];
    NSMutableDictionary *params11 = [NSMutableDictionary new];
    [params11 setValue:Token11 forKey:@"tokenId"];
    [params11 setValue:@"product" forKey:@"uploadType"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/GetUpyunFormParams" params:params11 success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSLog(@"%@",severDataDict.dataDict);
                
                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                NSString*policy=[severDataDict.dataDict objectForKey:@"policy"];
                NSString*signature=[severDataDict.dataDict objectForKey:@"signature"];
                NSString*action=[severDataDict.dataDict objectForKey:@"action"];
                [user setObject:signature forKey:@"signature"];
                [user setObject:policy forKey:@"policy"];
                [user setObject:action forKey:@"action"];
                [user synchronize];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    commdity=[HAODEsingleton shared];
    
    selectFeatureCodeArray=[[NSMutableArray alloc]init];
    specName=[[NSMutableArray alloc]init];
    specInv=[[NSMutableArray alloc]init];
    specPrice=[[NSMutableArray alloc]init];
    imageList=[[NSMutableArray alloc]init];
    imageArray1=[[NSMutableArray alloc]init];
    
    itemList=[[NSMutableArray alloc]init];
    self.title = @"修改案例";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,64, ScreenWidth, ScreenHeight)];
    [myscrollView setBackgroundColor: zuiqianhuicolor];
    
    myscrollView.delegate = self;
    myscrollView.userInteractionEnabled = YES;
    myscrollView.scrollEnabled = YES;
    myscrollView.showsVerticalScrollIndicator = FALSE;
    myscrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:myscrollView];
    imageArray = [NSMutableArray arrayWithArray:commdity.imageUrlFullarr1];
    imageList = [NSMutableArray arrayWithArray:commdity.imageUrls];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //设置单元格的尺寸
    flowLayout.itemSize = CGSizeMake(collectionCellHeight, collectionCellHeight);
    
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.minimumLineSpacing = 5;
    flowLayout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,10, ScreenWidth, collectionCellHeight+15*2) collectionViewLayout:flowLayout];
    _collectionView.layer.borderColor = LineColor.CGColor;
    [_collectionView.layer setBorderWidth:0.35];   //边
    
    _collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    
    [self.collectionView registerClass:[webCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [myscrollView addSubview:self.collectionView];
    
    
    
    
    
   
    
    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    
    view1=[[UIView alloc]initWithFrame:CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 225+120)];
    view1.backgroundColor=[UIColor whiteColor];
    [myscrollView addSubview:view1];
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 0.35)];
    line1.backgroundColor = labelColor;
    [view1 addSubview:line1];
    UILabel *line11 = [[UILabel alloc]initWithFrame:CGRectMake(15,45, ScreenWidth-30, 0.35)];
    line11.backgroundColor = labelColor;
    [view1 addSubview:line11];
    UILabel *line111 = [[UILabel alloc]initWithFrame:CGRectMake(15,90, ScreenWidth-30, 0.35)];
    line111.backgroundColor = labelColor;
    [view1 addSubview:line111];
    UILabel *line1111 = [[UILabel alloc]initWithFrame:CGRectMake(15,135, ScreenWidth-30, 0.35)];
    line1111.backgroundColor = labelColor;
    [view1 addSubview:line1111];
    UILabel *line12 = [[UILabel alloc]initWithFrame:CGRectMake(0,180, ScreenWidth, 0.35)];
    line12.backgroundColor = labelColor;
    [view1 addSubview:line12];
    UILabel *line13 = [[UILabel alloc]initWithFrame:CGRectMake(0,225-0.35, ScreenWidth, 0.35)];
    line13.backgroundColor = labelColor;
    [view1 addSubview:line13];
    
    
    UILabel* leibie=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, ScreenWidth-50,45)];
    leibie.text=[NSString stringWithFormat:@"%@", @"类别"];
    leibie.font=[UIFont systemFontOfSize:contenfot];
    leibie.textColor=[UIColor blackColor];
    [view1 addSubview:leibie];
    UIButton*jiantouBtn3 = [[UIButton alloc]init];
    jiantouBtn3.frame = CGRectMake(ScreenWidth-30,15,8, 13);
    [jiantouBtn3 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [view1 addSubview:jiantouBtn3];
   
    
    leibieTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  0, ScreenWidth*500/750,  45)];
    leibieTextFied.borderStyle = UITextBorderStyleNone;
    leibieTextFied.font = [UIFont systemFontOfSize: contenfot];
    leibieTextFied.textColor=[UIColor blackColor];
    leibieTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    leibieTextFied.tag=5;
    leibieTextFied.placeholder = @"请选择类别"; //默认显示的字
    [leibieTextFied setUserInteractionEnabled:NO];
    leibieTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:leibieTextFied];
    UIButton*leibieBtn=[[UIButton alloc]initWithFrame:CGRectMake(70, 0, ScreenWidth, 45)];
    [leibieBtn addTarget:self action:@selector(leibieBtn:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:leibieBtn];
    
    
    
    UILabel* mingcheng=[[UILabel alloc]initWithFrame:CGRectMake(20, 45, 70,45)];
    mingcheng.text=[NSString stringWithFormat:@"%@", @"风格"];
    mingcheng.font=[UIFont systemFontOfSize:contenfot];
    mingcheng.textColor=[UIColor blackColor];
    [view1 addSubview:mingcheng];
    UIButton*jiantouBtn1 = [[UIButton alloc]init];
    jiantouBtn1.frame = CGRectMake(ScreenWidth-30,60,8, 13);
    [jiantouBtn1 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [view1 addSubview:jiantouBtn1];
    mingchengTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  45, ScreenWidth*550/750,  45)];
    mingchengTextFied.borderStyle = UITextBorderStyleNone;
    mingchengTextFied.font = [UIFont systemFontOfSize: contenfot];
    mingchengTextFied.textColor=[UIColor blackColor];
    mingchengTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    mingchengTextFied.tag=6;
    mingchengTextFied.placeholder = @"请选择风格"; //默认显示的字
    [mingchengTextFied setUserInteractionEnabled:NO];
    mingchengTextFied.delegate = self;
    
    mingchengTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:mingchengTextFied];
    UIButton*fengge=[[UIButton alloc]initWithFrame:CGRectMake(70, 45, ScreenWidth, 45)];
    [fengge addTarget:self action:@selector(fengge:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:fengge];
    
    
    jiage=[[UILabel alloc]initWithFrame:CGRectMake(20, 90, 70,45)];
    jiage.text=[NSString stringWithFormat:@"%@", @"面积"];
    jiage.font=[UIFont systemFontOfSize:contenfot];
    jiage.textColor=[UIColor blackColor];
    [view1 addSubview:jiage];
    jiageTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  90, ScreenWidth*550/750,  45)];
    jiageTextFied.borderStyle = UITextBorderStyleNone;
    jiageTextFied.keyboardType=UIKeyboardTypeDecimalPad;
    jiageTextFied.font = [UIFont systemFontOfSize: contenfot];
    jiageTextFied.textColor=[UIColor blackColor];
    jiageTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    jiageTextFied.tag=7;
    [jiageTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    
    jiageTextFied.placeholder = @"请选择面积"; //默认显示的字
   jiageTextFied.text=[NSString stringWithFormat:@"%@",  [commdity.Dict objectForKey:@"caseArea"]];
    [jiageTextFied setUserInteractionEnabled:YES];
    jiageTextFied.delegate = self;
    jiageTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:jiageTextFied];
    jiage=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-40, 90, 30,45)];
    jiage.text=[NSString stringWithFormat:@"%@", @"m"];
    jiage.font=[UIFont systemFontOfSize:16];
    jiage.textColor=zhonghuiColor;
    [view1 addSubview:jiage];
    
    jiage=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-30, 90, 30,45)];
    jiage.text=[NSString stringWithFormat:@"%@", @"  2"];
    jiage.font=[UIFont systemFontOfSize:8];
    jiage.textColor=zhonghuiColor;
    [view1 addSubview:jiage];
    
    
    
    
    
    kucun=[[UILabel alloc]initWithFrame:CGRectMake(20, 135, 70,45)];
    kucun.text=[NSString stringWithFormat:@"%@", @"户型"];
    kucun.font=[UIFont systemFontOfSize:contenfot];
    kucun.textColor=[UIColor blackColor];
    [view1 addSubview:kucun];
    UIButton*jiantouBtn14 = [[UIButton alloc]init];
    jiantouBtn14.frame = CGRectMake(ScreenWidth-30,150,8, 13);
    [jiantouBtn14 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [view1 addSubview:jiantouBtn14];
    kucunTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  135, ScreenWidth*550/750,  45)];
    kucunTextFied.borderStyle = UITextBorderStyleNone;
    kucunTextFied.font = [UIFont systemFontOfSize: contenfot];
    kucunTextFied.textColor=[UIColor blackColor];
    kucunTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    kucunTextFied.tag=8;
    kucunTextFied.placeholder = @"请选择户型"; //默认显示的字
    [kucunTextFied setUserInteractionEnabled:NO];
    kucunTextFied.delegate = self;
  
    kucunTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:kucunTextFied];
    UIButton*huxing=[[UIButton alloc]initWithFrame:CGRectMake(70, 135, ScreenWidth, 45)];
    [huxing addTarget:self action:@selector(huxing:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:huxing];
    
    
    UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(20, 180, 70,45)];
    title.text=[NSString stringWithFormat:@"%@", @"标题"];
    title.font=[UIFont systemFontOfSize:contenfot];
    title.textColor=[UIColor blackColor];
    [view1 addSubview:title];
    titleTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  180, ScreenWidth*550/750,  45)];
    titleTextFied.borderStyle = UITextBorderStyleNone;
    titleTextFied.font = [UIFont systemFontOfSize: contenfot];
    titleTextFied.textColor=[UIColor blackColor];
    titleTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    titleTextFied.tag=9;
    titleTextFied.placeholder = @"请输入标题"; //默认显示的字
    [titleTextFied setUserInteractionEnabled:NO];
    titleTextFied.delegate = self;
    titleTextFied.text=  [commdity.Dict objectForKey:@"title"];
    titleTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:titleTextFied];
    
    
    view33=[[UIView alloc]initWithFrame:CGRectMake(0, titleTextFied.bottom, ScreenWidth, 10)];
    view33.backgroundColor=zuiqianhuicolor;
    [view1 addSubview:view33];
    UILabel *line131s = [[UILabel alloc]initWithFrame:CGRectMake(0,10, ScreenWidth, 0.35)];
    line131s.backgroundColor = qianhuicolor;
    [view33 addSubview:line131s];
    
    tv=[[UITextView alloc]init];
    tv.frame=CGRectMake(20, view33.bottom+10, ScreenWidth-40, 90);
    tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
    tv.scrollEnabled = YES;//是否可以拖动
    tv.delegate=self;
    tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
    tv.layer.borderWidth =0;
    CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
    [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
    tv.layer.cornerRadius =0;
  
    [view1 addSubview:tv];
    
    UILabel *line131ss = [[UILabel alloc]initWithFrame:CGRectMake(0,tv.bottom+10, ScreenWidth, 0.35)];
    line131ss.backgroundColor = qianhuicolor;
    [view1 addSubview:line131ss];
    
    
    
    
    if ([[commdity.Dict objectForKey:@"detail"]isEqualToString:@""]) {
        label=[[UILabel alloc]init];
        label.frame =CGRectMake(23, 10, ScreenWidth-60, 15);
        label.text = @"详情描述";
        label.textColor=zuiqianhuicolor;
        label.numberOfLines=0;
        label.font=[UIFont systemFontOfSize:15];
        label.enabled = NO;//lable必须设置为不可用
        label.backgroundColor = [UIColor clearColor];
        [tv addSubview:label];

        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 10, 51/3, 43/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
    }else{
        
        tv.text=[commdity.Dict objectForKey:@"detail"];
    }

    
    tv.inputAccessoryView = myToolBar;
    
    
    
    
    UIButton* baocun= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 30)];
    [baocun setTitle:@"保存" forState:UIControlStateNormal];
    [baocun setTitleColor:luseColor forState:UIControlStateNormal];
    [baocun addTarget:self action:@selector(baocun:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:baocun];
    self.navigationItem.rightBarButtonItem = leftBarButton;
    
    
    jiageTextFied.inputAccessoryView = myToolBar;
    leibieTextFied.inputAccessoryView = myToolBar;
    mingchengTextFied.inputAccessoryView = myToolBar;
    titleTextFied.inputAccessoryView = myToolBar;
    kucunTextFied.inputAccessoryView = myToolBar;

    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* tokenId = [user objectForKey:@"tokenId"];
    
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:tokenId forKey:@"tokenId"];
    
    [params setValue:commdity.caseID forKey:@"caseID"];
    [HttpRequest requestData:@"Business/Case/ItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                imageArray1 = [NSMutableArray arrayWithObjects:nil];
                
                itemList = [[NSMutableArray alloc]init];
                imageArray1 = [[NSMutableArray alloc]init];

                
                NSArray *product = [severDataDict.dataDict objectForKey:@"DataLine"];
                
                
                view=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 250)];
                view.backgroundColor=[UIColor whiteColor];
                [myscrollView addSubview:view];
                
                
                for (NSDictionary* dicc in product )
                {
                    [itemList addObject:[dicc valueForKey:@"itemId"]];
                    [imageArray1 addObject:[dicc valueForKey:@"imageUrlFull"]];
                    
                    
                }

                commdity.itemIdarr=[itemList mutableCopy];
                commdity.imageUrlFullarr=[imageArray1 mutableCopy];
                
                if (imageArray1.count>0) {
                    
                    
                    for (int i = 0,j = -1; i <imageArray1.count+1; i++) {
                        if (i%4 == 0) {
                            j++;
                        }
                        if (imageArray1.count==i) {
                            UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15+(ScreenWidth-30)/4*(i%4), 20+(ScreenWidth-40)/4*j, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                            [imageView setImage:[UIImage imageNamed:@"tianjiatupain"] forState:UIControlStateNormal];
                            [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                            imageView.tag=imageArray1.count;
                            [view addSubview:imageView];
                        }else{
                            UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15+(ScreenWidth-30)/4*(i%4), 20+(ScreenWidth-40)/4*j, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                            [imageView setImageWithURL:[NSURL URLWithString:[imageArray1  objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@""]];
                            [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                            imageView.tag=i;
                            [view addSubview:imageView];
                        }
                        
                    }
                }else{
                    UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15, 20, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                    [imageView setImage:[UIImage imageNamed:@"tianjiatupain"] forState:UIControlStateNormal];
                    [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                    imageView.tag=imageArray1.count;
                    [view addSubview:imageView];
                }

                
                
                
                
                myscrollView.frame=CGRectMake(0, 64, ScreenWidth, ScreenHeight-64);
                myscrollView.contentSize = CGSizeMake(ScreenWidth,view.bottom);
                
                
            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
            
            
            
        }
        
    }];

    

    
    
}
-(void)shanchus{
    
    
    [view removeFromSuperview];
    view=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 250)];
    view.backgroundColor=[UIColor whiteColor];
    [myscrollView addSubview:view];
    
    
    if (imageArray1.count>0) {
        
        
        for (int i = 0,j = -1; i <imageArray1.count+1; i++) {
            if (i%4 == 0) {
                j++;
            }
            if (imageArray1.count==i) {
                UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15+(ScreenWidth-30)/4*(i%4), 20+(ScreenWidth-40)/4*j, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                [imageView setImage:[UIImage imageNamed:@"tianjiatupain"] forState:UIControlStateNormal];
                [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                imageView.tag=imageArray1.count;
                [view addSubview:imageView];
            }else{
                UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15+(ScreenWidth-30)/4*(i%4), 20+(ScreenWidth-40)/4*j, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
                [imageView setImageWithURL:[NSURL URLWithString:[imageArray1  objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@""]];
                [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
                imageView.tag=i;
                [view addSubview:imageView];
            }
            
        }
    }else{
        UIButton* imageView  = [[UIButton alloc]initWithFrame:CGRectMake(15, 20, (ScreenWidth-50)/4, (ScreenWidth-50)/4)];
        [imageView setImage:[UIImage imageNamed:@"tianjiatupain"] forState:UIControlStateNormal];
        [imageView addTarget:self action:@selector(addtup:) forControlEvents:UIControlEventTouchUpInside];
        imageView.tag=imageArray1.count;
        [view addSubview:imageView];
    }
    
    
    
    
    
    
}

-(void)addtup:(UIButton*)sender{
    
    
    
    
    sat=nil;
    sat=@"guanglian";
    commdity.how=@"anli";
    if (sender.tag == imageArray1.count)
    {
        commdity.how=@"anli";
        GetProductListViewController*detailViewController = [[GetProductListViewController alloc] init];
        [self.navigationController pushViewController:detailViewController animated:YES];
        
    }
    else
    {
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"确定删除" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alertView.tag =sender.tag;
        [alertView show];
    }
    
    //    GetProductListViewController*detailViewController = [[GetProductListViewController alloc] init];
    //    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
    
}



- (void)textFieldDidChange:(UITextField *) TextField{
    
    if (TextField.tag == 7)
        
    {
        
        titleTextFied.text=[NSString stringWithFormat:@"%@ %@㎡ %@",mingchengTextFied.text,jiageTextFied.text,kucunTextFied.text];
        
    }
}

//上传数据
-(void)baocun:(UIButton*)sender{
    [imageList removeAllObjects];
    [self  upToUpYun];
    
}


-(void)upToUpYun
{
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    for (int i=0; i<imageArray.count; i++) {
        
        UIImage *portraitImg = [[UIImage alloc]init];
        portraitImg = [self imageByScalingToMaxSize:imageArray[i]];
        //        VPImageCropperViewController *imgEditorVC = [[VPImageCropperViewController alloc] initWithImage:portraitImg cropFrame:CGRectMake(0, 100.0f, ScreenWidth, ScreenWidth) limitScaleRatio:3];
        
        UpYun *uy = [[UpYun alloc] init];
        uy.successBlocker = ^(id data)
        {
            
            
            NSString *imageURL;
            NSString *imageWIDTH;
            NSString *imageHEIGHT;
            imageURL=[data objectForKey:@"url"];
            imageWIDTH=[data objectForKey:@"image-width"];
            imageHEIGHT=[data objectForKey:@"image-height"];
            NSMutableDictionary *upYunImageDict=[NSMutableDictionary dictionary];
            [upYunImageDict setObject:imageURL forKey:@"imageUrl"];
            [upYunImageDict setObject:imageWIDTH forKey:@"imageWidth"];
            [upYunImageDict setObject:imageHEIGHT forKey:@"imageHeight"];
            
            [imageList addObject:upYunImageDict];
            
            NSLog(@"--------－－－－%ld",imageList.count);
            NSLog(@"--------－－－－%ld",imageArray.count);
            if (imageList.count==imageArray.count) {
                
                [Global hideProgressHUDInternal:self.view];
                NSLog(@"--------－－－－%@",imageList);
                [self  baocunxia];
            }
            
        };
        uy.failBlocker = ^(NSError * error)
        {
            [Global hideProgressHUDInternal:self.view];
            
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"上传失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            NSLog(@"%@",error);
        };
        uy.progressBlocker = ^(CGFloat percent, long long requestDidSendBytes)
        {
            
        };
        
        [uy uploadFile:portraitImg saveKey:[self getSaveKey]];
        
        //        imgEditorVC.delegate = self;
        
        
    }
}
-(void)baocunxia{
    
    
    
    
    if ([leibieTextFied.text length] < 1)
    {
        [self showAlertMessage:@"请选择类别"];
    }
    else
    {
        
        if ([jiageTextFied.text length] <1)
        {
            [self showAlertMessage:@"请输入面积"];
        }
        else{ if ([titleTextFied.text length] <1)
        {
            [self showAlertMessage:@"请输入标题"];
        }
        else{
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            
            [params setValue:Token forKey:@"tokenId"];
            
            [params setValue:@"U" forKey:@"editType"];
           
            [params setValue:commdity.caseID forKey:@"caseID"];
            
            
            
            [params setValue:mingchengTextFied.text forKey:@"itemName"];
            [params setValue:commdity.code forKey:@"typeCode"];
            [params setValue:commdity.caseStyleCode forKey:@"caseStyleCode"];
            [params setValue:jiageTextFied.text forKey:@"caseArea"];
            [params setValue:commdity.caseHouseCode forKey:@"caseHouseCode"];
            
            [params setValue:titleTextFied.text forKey:@"title"];
            [params setValue:tv.text forKey:@"detail"];
            
            
            [params setValue:imageList  forKey:@"imageList"];
            NSMutableArray *mDocumentLine=[NSMutableArray array];
            
            
            for (int i=0; i<itemList.count; i++) {
                
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                NSString *codeStr = [itemList objectAtIndex:i];
                [dic setValue:codeStr forKey:@"itemID"];
                [mDocumentLine addObject:dic];
                
                
            }
            
            NSLog(@"====%@",mDocumentLine);
            [params setValue:mDocumentLine  forKey:@"itemList"];
            
            
            NSLog(@"33333333====%@",params);
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
            
            [HttpRequest requestData:@"Business/Case/Edit" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"33333333====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        
                        commdity.gengxin=@"";
                        commdity.gengxinxiangqing=@"";
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        [self.navigationController popViewControllerAnimated:YES];
                        
                        
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }
        }
        
    }}




- (void)textFieldDidEndEditing:(UITextField *)textField
{
    
    
}
- (void)customLayout
{
    
    int numberOfLines = (int)ceil([self collectionView:self.collectionView numberOfItemsInSection:0] / 4.0);
    
    CGRect frame = self.collectionView.frame;
    frame.size.height = numberOfLines *collectionCellHeight + (numberOfLines - 1) * 5 + 15*2;
    self.collectionView.frame = frame;
    
    
    if (specName.count==0) {
        view1.frame=CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 225+120);
    }else{
        
        view1.frame=CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 100);
    }
    
    view.frame = CGRectMake(0,view1.bottom+10, ScreenWidth, 250);
    myscrollView.frame=CGRectMake(0, 64, ScreenWidth, ScreenHeight-64);
    myscrollView.contentSize = CGSizeMake(ScreenWidth,view.bottom );
    
    
    
}

-(void)huxing:(UIButton*)sender{
    
    huxingViewController *detailViewController = [[huxingViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
}
-(void)fengge:(UIButton*)sender{
    
    fenggeViewController *detailViewController = [[fenggeViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
}

-(void)leibieBtn:(UIButton*)sender{
    //用案例类别
    mianjiViewController *detailViewController = [[mianjiViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    if (textField.tag == 7)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        myscrollView .frame =CGRectMake(0, -50, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }if (textField.tag ==6)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        myscrollView .frame =CGRectMake(0, -50, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
    }
    if (textField.tag ==8)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        myscrollView .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
    }
    if (textField.tag ==9)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        myscrollView .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
    }
    
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    myscrollView .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    return self;
}

-(void)textViewDidChange:(UITextView *)textView
{
    // self.examineText =  textView.text;
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 10, 51/3, 51/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label.text = @"详情描述";
        
    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //
    //    if (collectionView == _collectionView1) {
    //     return imageArray1.count+1;
    //    }
    //
    return imageArray.count+1;
    
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * string = @"cell";
    webCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:string forIndexPath:indexPath];
    
    if (collectionView == _collectionView) {
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:string forIndexPath:indexPath];
        
        if (indexPath.row ==imageArray.count) {
            
            cell.imgView.image = [UIImage imageNamed:@"tianjiatupain"];
        }else{
            
            cell.imgView.image = imageArray[indexPath.row];
        }
        
    }
    
    
    
    
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    if (collectionView == self.collectionView) {
        sat=nil;
        sat=@"";
        if (indexPath.item == imageArray.count)
        {
            UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选择", nil];
            [actionSheet showInView:self.view];
        }
        else
        {
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"确定删除" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alertView.tag = indexPath.row;
            [alertView show];
        }
        
        
    }
    
    
    
    
}
#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        // 拍照
        if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos]) {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            controller.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
            controller.mediaTypes = mediaTypes;
            controller.delegate = self;
            controller.allowsEditing = YES;
            //            controller.showsCameraControls=true;
            [self presentViewController:controller
                               animated:YES
                             completion:^(void){
                                 NSLog(@"Picker View Controller is presented");
                             }];
        }
        
    } else if (buttonIndex == 1) {
        // 从相册中选取
        if ([self isPhotoLibraryAvailable]) {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
            controller.mediaTypes = mediaTypes;
            controller.delegate = self;
            controller.allowsEditing = YES;
            //            controller.showsCameraControls=NO;
            [self presentViewController:controller
                               animated:YES
                             completion:^(void){
                                 NSLog(@"Picker View Controller is presented");
                             }];
        }
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ([sat isEqualToString:@""]) {
        if (buttonIndex == 1)
        {
            
            NSLog(@"-----%ld",alertView.tag);
            NSLog(@"-----%@",imageArray);
            NSMutableArray*imageUrl = [[NSMutableArray alloc] init];
            imageUrl = [NSMutableArray arrayWithArray:imageArray];
            [imageUrl removeObjectAtIndex:alertView.tag];//从指定索引移除
            
            imageArray=[[NSMutableArray alloc]init];
            imageArray = [NSMutableArray arrayWithObjects:nil];
            
            imageArray=imageUrl;
            
            [_collectionView reloadData];
            
            [self customLayout];
            
        }if (buttonIndex == 0)
        {
            
            
            
        }
        
    }
    
    
    
    
    
    
    
    
    if ([sat isEqualToString:@"guanglian"]) {
        
        if (buttonIndex == 1)
        {
            
            
            NSMutableArray*imageUrl = [[NSMutableArray alloc] init];
            imageUrl = [NSMutableArray arrayWithArray:commdity.imageUrlFullarr];
            [imageUrl removeObjectAtIndex:alertView.tag];//从指定索引移除
           
            commdity.imageUrlFullarr= imageUrl;
            
            itemList = [[NSMutableArray alloc] init];
            itemList = [commdity.itemIdarr mutableCopy];
           
            [itemList removeObjectAtIndex:alertView.tag];//从指定索引移除
            commdity.itemIdarr= itemList;
            itemList=commdity.itemIdarr;
            
            imageArray1=[[NSMutableArray alloc]init];
            imageArray1 = [NSMutableArray arrayWithObjects:nil];
            
            imageArray1=commdity.imageUrlFullarr;
            [self shanchus];
            
        }
        if (buttonIndex == 0)
        {
            
            
            
        }
        
        
    }
    
    
    
}






//图像选取器的委托方法，选完图片后回调该方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage* image = [info valueForKey:UIImagePickerControllerEditedImage];
    if (image != nil)
    {
        
        
        
        
        [imageArray addObject:image];
        NSLog(@"－－－－－－－-----%@",imageArray);
        [_collectionView reloadData];
        [self customLayout];
        
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}


-(void)OnTapDone{
    
    [tv resignFirstResponder];
    [jiageTextFied resignFirstResponder];
    [leibieTextFied resignFirstResponder];
    [mingchengTextFied resignFirstResponder];
    [kucunTextFied resignFirstResponder];
    [titleTextFied resignFirstResponder];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    myscrollView .frame =CGRectMake(0, 64, ScreenWidth, ScreenHeight-64);
    [UIView commitAnimations];
    
    //    [_table reloadData];
    
}


- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSString * )getSaveKey {
    /**
     *	@brief	方式1 由开发者生成saveKey
     */
    NSDate *d = [NSDate date];
    return [NSString stringWithFormat:@"/%d/%d/%.0f.png",[self getYear:d],[self getMonth:d],[[NSDate date] timeIntervalSince1970]];
    
    /**
     *	@brief	方式2 由服务器生成saveKey
     */
    //    return [NSString stringWithFormat:@"/{year}/{mon}/{filename}{.suffix}"];
    
    /**
     *	@brief	更多方式 参阅 http://wiki.upyun.com/index.php?title=Policy_%E5%86%85%E5%AE%B9%E8%AF%A6%E8%A7%A3
     */
    
}
//#pragma mark VPImageCropperDelegate
//- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage {
//
//
//    [cropperViewController dismissViewControllerAnimated:YES completion:^{
//        // TO DO
//    }];
//}
//
//- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController {
//    [cropperViewController dismissViewControllerAnimated:YES completion:^{
//    }];
//}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^(){
    }];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
}

#pragma mark camera utility
- (BOOL) isCameraAvailable{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isRearCameraAvailable{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

- (BOOL) isFrontCameraAvailable {
    return nil;
}

- (BOOL) doesCameraSupportTakingPhotos {
    return [self cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isPhotoLibraryAvailable{
    return [UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickVideosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickPhotosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType{
    __block BOOL result = NO;
    if ([paramMediaType length] == 0) {
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType]){
            result = YES;
            *stop= YES;
        }
    }];
    return result;
}
#define ORIGINAL_MAX_WIDTH 420.0f
#pragma mark image scale utility
- (UIImage *)imageByScalingToMaxSize:(UIImage *)sourceImage {
    if (sourceImage.size.width < ORIGINAL_MAX_WIDTH) return sourceImage;
    CGFloat btWidth = 0.0f;
    CGFloat btHeight = 0.0f;
    if (sourceImage.size.width > sourceImage.size.height) {
        btHeight = ORIGINAL_MAX_WIDTH;
        btWidth = sourceImage.size.width * (ORIGINAL_MAX_WIDTH / sourceImage.size.height);
    } else {
        btWidth = ORIGINAL_MAX_WIDTH;
        btHeight = sourceImage.size.height * (ORIGINAL_MAX_WIDTH / sourceImage.size.width);
    }
    CGSize targetSize = CGSizeMake(btWidth, btHeight);
    return [self imageByScalingAndCroppingForSourceImage:sourceImage targetSize:targetSize];
}

- (UIImage *)imageByScalingAndCroppingForSourceImage:(UIImage *)sourceImage targetSize:(CGSize)targetSize {
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth  = width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else
            if (widthFactor < heightFactor)
            {
                thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
            }
    }
    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil) NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}


- (int)getYear:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSYearCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    return year;
}

- (int)getMonth:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSMonthCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int month = [comps month];
    return month;
}
-(UIImage *)imageCompress:(UIImage *)image11
{
    UIImage *comImage=image11;
    NSData * sendImageData = UIImageJPEGRepresentation(comImage, 1.0);
    NSUInteger sizeOrigin = [sendImageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    
    if (sizeOriginKB >400) {
        float a = 800.0000;
        float b = (float)sizeOriginKB;
        float q = sqrtf(a / b);
        
        CGSize sizeImage = [comImage size];
        CGFloat widthSmall = sizeImage.width * q;
        CGFloat heighSmall = sizeImage.height * q;
        CGSize sizeImageSmall = CGSizeMake(widthSmall, heighSmall);
        
        UIGraphicsBeginImageContext(sizeImageSmall);
        CGRect smallImageRect = CGRectMake(0, 0, sizeImageSmall.width, sizeImageSmall.height);
        [image11 drawInRect:smallImageRect];
        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        NSData *dataImage = UIImageJPEGRepresentation(smallImage, 1.0);
        sendImageData = dataImage;
        NSLog(@"11111111%f",sizeImageSmall.width);
        NSLog(@"11111111%f",sizeImageSmall.height);
        comImage= smallImage;
        // [_imageview1.image retain];
    }
    return comImage;
}

@end

